#!/usr/bin/env python
# -*- coding:utf-8 -*- 
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:

"""
@version: 1.0
@author: readerror
@contact: readerror@readerror.cn
@contact1: readerror000@gmail.com
@site: http://www.readerror.cn
@software: PyCharm
@file: cluster.py
@time: 2017/3/22 10:19
"""


class ClusterApiMixin(object):
    def api_call(self, api, data, async=False, period=60.0):
        NotImplementedError()

    def get_api_result(self, res, api_name=False):
        NotImplementedError()

    # def query_cluster(self, data=None, async=False):
    #     """
    #     QueryCluster
    #     :param async: Can be used to asynchronously execute code.
    #     :param data:
    #     {'conditions': [], 'session': {'uuid': 'c8c1837862b34e3d92a3c435d02c3aaf'}}
    #     """
    #     if data is None:
    #         data = {}
    #     if data.get('conditions') is None:
    #         data['conditions'] = []
    #     rsp = self.api_call("org.zstack.header.cluster.APIQueryClusterMsg", data, async=async)
    #     return self.get_api_result(rsp)

    def query_cluster(self, data=None, async=False):
        """
        QueryCluster
        :param async: Can be used to asynchronously execute code.
        :param data:
        {'conditions': [], 'session': {'uuid': 'b0c42025c7aa40a8854e6f62e5ead653'}}
        """
        if data is None:
            data = {}
        if data.get('conditions') is None:
            data['conditions'] = []
        rsp = self.api_call("org.zstack.header.cluster.APIQueryClusterMsg", data, async=async)
        return self.get_api_result(rsp)
